{{if false}}<script>{{/if}}
{{$controller = $smarty.const.CCTRL}}
{{$token = $smarty.const.TOKEN}}
{{include file="../00_base/_function.tpl"}}
function handleEvents(){
    try{
        acolumns['_id'].cellsrenderer = function (row, column, value) {
            return "<span class='a lh24 pl8' title='"+value+"'>" + value.substring(0, 10).toUpperCase() + "</span>";
        }
        acolumns['_value'].validation= function (cell, value) {
            if (value < 0 || value > 100) {
                return { result: false, message: "Position should be in the 0-100 interval" };
            }
            return true;
        };
        acolumns['_value'].createeditor=function (row, cellvalue, editor) {
            editor.jqxNumberInput({ decimalDigits: 0 });
        };
    }catch(e){tipMessage(e.message);}
}
function SaveItem(){

}
    $(document).ready(function(){
        uitooltip();
        return;
        var theme=getTheme();
        var source ={
            datatype: "json",
            type        :   "POST",
            datafields  : [
                { name: '_id'           , type: 'string' },
                { name: '_name'         , type: 'string' },
                { name: '_description'  , type: 'string' },
                { name: '_status'       , type: 'bool' },
                { name: '_insert'       , type: 'string' },
                { name: '_update'       , type: 'string' },
                { name: '_delete'       , type: 'string' }
            ],
            url         : '{{base_url()}}backend/category/binding',
            //        filter      : function(){ 
            //            $("#jqxGrid").jqxGrid('updatebounddata', 'filter') 
            //        },
            sort        : function(){ 
                $("#jqxGrid").jqxGrid('updatebounddata') 
            },
            root        : 'Rows',
            beforeprocessing: function(data){		
                source.totalrecords = data[0].TotalRows;					
            }
        };	
        var dataadapter = new $.jqx.dataAdapter(source, {
            loadError: function(xhr, status, error){
                ShowErrorDialogMessage("<b>Status</b>:"+xhr.status+"<br/><b>ThrownError</b>:"+error+"<br/>");
            }
        });
        $("#jqxGrid").jqxGrid({
            width:'100%',
                
            autoheight: true,
            //rowsheight: 24,
            source: dataadapter,
            theme: theme,
            sortable: true,
            ready: function () {

            },
            rendergridrows: function(obj)
            {
                return obj.data;    
            },

            //groupable:true,
            //filterable: true,
            //autoshowfiltericon: true,
            //showfilterrow: true,
            editable:true,
            editmode:'dblclick',
            selectionmode:'singlecell',
            //showaggregates: true,
            //showstatusbar: true,
            //statusbarheight: 50,
            //height:$(document).height() - 40,
            virtualmode: true,
            columns: [
                { text: 'ID'        , datafield: '_id'      , width: 100 ,editable:false},
                { text: 'Name'      , datafield: '_name'    , minwidth: 100 ,
                    validation: function (cell, value) {
                        if (value =="") {
                            return { result: false, message: "Name should be non-empty." };
                        }
                        return true;
                    }
                },
                { text: 'Description'   , datafield: '_description' , width: 200 },
                { text: 'Status'        , datafield: '_status'      , width: 100 ,editable:false},
                { text: 'Insert'        , datafield: '_insert' , width: 100 }
            ]
        }).bind('cellendedit', function (event) {
            try{
                var args = event.args;
                var Column = args.datafield ,Row = args.rowindex,Value = args.value;
                var dataRow = $("#jqxGrid").jqxGrid('getrowdata', Row);
                var _id=dataRow._id;
                if(_id==undefined || _id==""){
                    return;
                }
                switch(Column){
                    case "_name":
                        if(dataRow._name!=Value){
                            updateCol(_id,"_name",Value);
                        }
                        break;
                    case "_amount":
                        if(dataRow._amount!=Value){
                            updateCol(_id,"_amount",Value);
                        }
                        break;
                    case "_percent":
                        if(dataRow._percent!=Value){
                            updateCol(_id,"_percent",Value);
                        }
                        break;
                    default:
                        
                }
            }catch(e){
                ShowErrorDialogMessage(e.message);
                console.log("Error:"+e.message);
            }
        });
    });
{{if false}}</script>{{/if}}